﻿using OSS.BIM.Business;
using OSS.BIM.Model;
// ***********************************************************************
// Assembly         : OSS.BIM
// Author           : tianteng
// Created          : 03-16-2018
//
// Last Modified By : tianteng
// Last Modified On : 03-16-2018
// ***********************************************************************
// <copyright file="DeleteGroupCmd.cs" company="北京智帆高科科技有限公司">
//     Copyright ©  2017
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Windows.Forms;
using OSS.BIM.Utility;
using ZFGK.Addins;
using ZFGK.Utility;

namespace OSS.BIM.Commands.GroupCmds
{
    /// <summary>
    /// Class DeleteGroupCmd.
    /// </summary>
    /// <seealso cref="ZFGK.Addins.IExtendCommand" />
    public class GroupDeleteCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var userGroup = cmdData.Tag as ModelGrope;
            if (userGroup == null)
                userGroup = CurUserGroup.Instance.ModelGrope;
            if (userGroup == null)
            {
                ZfMessageUtil.ShowError("当前分组为空!");
                return CmdResult.Cancel;
            }

            if (CurUserGroup.Instance.ModelGrope != null && userGroup.ModelGropeId == CurUserGroup.Instance.ModelGrope.ModelGropeId)
            {
                ZfMessageUtil.ShowError("当前活动分组不能删除！");
                return CmdResult.Cancel;
            }
            if (MessageBox.Show("确认要删除该分组?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
            {
                return CmdResult.Cancel;
            }
            if (DB.Context.Delete(userGroup) <= 0)
            {
                ZfMessageUtil.ShowError("更新数据库失败!", "数据库错误");
                return CmdResult.Cancel;
            }
            userGroup.DeleteTreeNode();

            return CmdResult.Succeed;
        }
    }
}
